package com.example.Gethome.repository;

import com.example.Gethome.entity.Administrator;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface AdminRepository extends JpaRepository<Administrator, Integer> {

    // 管理员通过用户名和密码进行登录
    @Transactional
    @Query("select a from Administrator a where a.username = ?1 and a.password = ?2")
    List<?> findByUsernameAndPassword(String username, String password);

    // 管理员可以更改自己的密码
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query("update Administrator set username = ?1 where password = ?2")
    void updateAdminPassword(String username, String password);
}
